package cn.dckeji.gameBox.common.utils;

import cn.dckeji.gameBox.common.constants.Constants;
import cn.dckeji.gameBox.dto.Result;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Lucas
 * @date 2018/1/23
 * @package cn.dckeji.gameBox.common.utils
 * @Description 返回对象工具类
 */
public class ResultUtil {

    /* 成功有值*/
    public static Result success(Object object) {
        Result result = new Result();
        result.setCode(Constants.SUCCESS);
        result.setMsg(Constants.MSG_SUCCESS);
        result.setData(object);
        return result;
    }

    /* 成功无值*/
    public static Result success() {
        return success(null);
    }


    /* 失败*/
    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(Constants.ERROR);
        result.setMsg(msg);
        return result;
    }


    /**
     * 放回分页查询结果
     * @param count
     * @param object
     * @return
     */
    public static JSONObject resultPage(Integer count,Object object) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("count",count);
        jsonObject.put("data",object);
        jsonObject.put("msg","请求成功");
        return jsonObject;
    }
}
